package com.jrtc.backend.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.google.common.base.Strings;
import com.jrtc.base.config.dto.ResultDTO;
import com.jrtc.base.config.dto.ResultDTOBuilder;
import com.jrtc.base.entity.bo.PrescriptionVideo;
import com.jrtc.service.PrescriptionVideoService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Map;

/**
 * 运动处方动作视频表(PrescriptionVideo)表控制层
 *
 * @author makejava
 * @since 2022-09-09 15:26:45
 */
@RestController
@RequestMapping("prescriptionVideo")
public class PrescriptionVideoController {
    /**
     * 服务对象
     */
    @Resource
    private PrescriptionVideoService prescriptionVideoService;

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("selectOne")
    public PrescriptionVideo selectOne(Integer id) {
        return this.prescriptionVideoService.queryById(id);
    }
    
    @RequestMapping("getPrescriptionVideoList")
    public ResultDTO getPrescriptionVideoList(@RequestBody PrescriptionVideo prescriptionVideo)
    {
        IPage<PrescriptionVideo> ipage = prescriptionVideoService.queryPrescriptionVideoList(prescriptionVideo);
        return ResultDTOBuilder.success(ipage);
    }

    @RequestMapping("insertPrescriptionVideo")
    public ResultDTO insertPrescriptionVideo(@RequestBody PrescriptionVideo prescriptionVideo)
    {
        PrescriptionVideo tmpPrescriptionVideo = prescriptionVideoService.insert(prescriptionVideo);
        if (tmpPrescriptionVideo != null)
        {
           return ResultDTOBuilder.success("添加成功！");
        }
        return ResultDTOBuilder.failureMsg("添加失败！");
    }

    @RequestMapping("getPrescriptionVideoById")
    public ResultDTO getPrescriptionVideoById(@RequestBody Map<String, String> map)
    {
        String prescriptionVideoId = map.get("prescriptionVideoId");
        PrescriptionVideo prescriptionVideo = prescriptionVideoService.queryById(Integer.valueOf(prescriptionVideoId));
        if (Strings.isNullOrEmpty(prescriptionVideoId) || prescriptionVideo==null)
        {
            return ResultDTOBuilder.failureMsg("信息有误！");
        }
        return ResultDTOBuilder.success(prescriptionVideo);
    }

    @RequestMapping("updatePrescriptionVideo")
    public ResultDTO updatePrescriptionVideo(@RequestBody PrescriptionVideo prescriptionVideo)
    {
        if (prescriptionVideo==null)
        {
            return ResultDTOBuilder.failureMsg("信息有误！");
        }
        if (prescriptionVideoService.update(prescriptionVideo)!=null)
        {
            return ResultDTOBuilder.success("修改信息成功！");
        }
        return ResultDTOBuilder.failureMsg("修改信息失败！");
    }
    
    @RequestMapping("deletePrescriptionVideo")
    public ResultDTO deletePrescriptionVideo(@RequestBody Map<String,String> map)
    {
        String prescriptionVideoId = map.get("prescriptionVideoId");
        if (!Strings.isNullOrEmpty(prescriptionVideoId))
        {
            if (prescriptionVideoService.deleteById(Integer.valueOf(prescriptionVideoId)))
            {
                return ResultDTOBuilder.success("删除成功！");
            }
            return ResultDTOBuilder.failureMsg("删除失败！");
        }
        return ResultDTOBuilder.failureMsg("编号不正确！");
    }
}